package com.komodo.island.gdx.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.Persistence;
import com.komodo.island.gdx.dialog.Dialog;

public class HelpScreen extends StoryScreen {

	public static final int SUIT = 1;
	public static final int PHOTO = 2;
	public static final int UNDERWATER = 5;
	public static final int BALANCE = 0;
	public static final int CASTLE = 4;
	public static final int MOVE = 3;
	public static final int SHOPPING = 6;

	private int helpLevel;
	private Dialog help;

	// private TextureRegion region;

	public HelpScreen(TextureRegion[] scene, int sceneNumber, double interval,
			Screen nextScreen) {
		super(scene, sceneNumber, interval, nextScreen);
		// TODO Auto-generated constructor stub

	}

	@Override
	public void init(KomodoIsland komodoIsland, Texture texture) {
		// TODO Auto-generated method stub
		super.init(komodoIsland, texture);
		if (scene == null) {
			scene = new TextureRegion[7];

			// if (helpLevel==BALANCE){
			scene[BALANCE] = new TextureRegion(texture, 0, 0, 320, 240);
			// }else if (helpLevel==CASTLE){
			scene[CASTLE] = new TextureRegion(texture, 320, 0, 320, 240);
			// }else if (helpLevel==MOVE){
			scene[MOVE] = new TextureRegion(texture, 320 * 2, 0, 320, 240);
			// }else if (helpLevel==SUIT){
			scene[SUIT] = new TextureRegion(texture, 0, 240, 320, 240);
			// }else if (helpLevel==PHOCTO){
			scene[PHOTO] = new TextureRegion(texture, 320, 240, 320, 240);
			// }else if (helpLevel==UNDERWATER){
			scene[UNDERWATER] = new TextureRegion(texture, 320 * 2, 240, 320,
					240);
			// }else if (helpLevel==SHOPPING){
			scene[SHOPPING] = new TextureRegion(texture, 0, 240 * 2, 320, 240);
			// }

		}

		if (help == null)
			help = new Dialog(480, 320, true, this, komodoIsland.helpTexture,komodoIsland) {
				Image bg;

				// public Image desc;

				@Override
				public void setThePosition() {
					// TODO Auto-generated method stub
					addActor(bg);
					// addActor(desc);
					// desc.x = 143;
					// desc.y = 70;

				}

				@Override
				public void setTheListener() {
					// TODO Auto-generated method stub

				}

				@Override
				public void init() {
					// TODO Auto-generated method stub
					// if (bg==null)
					bg = new Image("bg", new TextureRegion(texture, 960, 0,
							480, 320));
					// if (desc ==null)
					// desc = new Image("desc",scene[helpLevel]);
					// else
					// desc.region=scene[helpLevel];
				}

				@Override
				public void addElements() {
					// TODO Auto-generated method stub

				}

			};
	}

	public void setHelp(int level) {
		helpLevel = level;
		restartStory();
	}

	@Override
	public void onScreenRun() {
		// TODO Auto-generated method stub

		if (currScene < sceneNumber) {
			currTime = System.currentTimeMillis();
			if (currTime - startTime <= interval) {
				if (scene != null) {
					help.draw();
					help.getSpriteBatch().begin();

					help.getSpriteBatch().draw(scene[helpLevel], 145, 70);
					help.getSpriteBatch().end();

				}
				// Art.drawString(currScene + "", 0, 0);

				if (Gdx.input.justTouched()) {
					startTime = currTime;
					currScene++;
					if (Persistence.sound)
						komodoIsland.dialogSound.play(1);
				}

			} else {
				startTime = currTime;
				currScene++;
			}
		} else {
			komodoIsland.goToScreen(nextScreen);
		}

	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		super.hide();
		if (nextScreen instanceof MapScreen)
			((MapScreen) nextScreen).showGameDesc(helpLevel);
		else if (nextScreen instanceof GameScreen) {
			((GameScreen) nextScreen).resumeGame();
		}
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		super.dispose();

	}

	@Override
	public void cleanResScreen() {
		// TODO Auto-generated method stub
		super.cleanResScreen();
		try {
			help.dispose();
		} catch (Exception e) {

		}
	}

}
